<%@ taglib prefix="tiles" uri="http://tiles.apache.org/tags-tiles" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<%@ taglib prefix="security" uri="http://www.springframework.org/security/tags" %>

<h1>Question Tag List</h1>

<div id="tags">
	<table class="summary">
		<thead>
			<tr>
				<th>Name</th>
				<th>Count</th>
				<th>RegionId</th>
			</tr>
		</thead>
		<tbody>
			<c:forEach var="questionTag" items="${questionTagList}">
			<tr>
				<td>
					<a href="<c:url value="/questions/tags/${questionTag.name}" />"><c:out value="${questionTag.name}" escapeXml="true" /></a>
				</td>
				<td>${questionTag.questionCount}</td>
				<td>${questionTag.regionId}</td>
			</tr>
			</c:forEach>
		</tbody>
	</table>
</div>
<c:if test="${totalPages > 0}">
<div id="pages">
	<c:if test="${currentNumber > 1 }">
		<a href="<c:url value="/questions/tags?page=${currentNumber-1}"/>">&lt;</a>
	</c:if>
	<c:choose> 
		<c:when test="${totalPages <= 7 }">
			<c:forEach var="pageNumber" begin="1" end="${totalPages}">
				<a href="<c:url value="/questions/tags?page=${pageNumber}"/>">${pageNumber}</a>
			</c:forEach>
		</c:when>
		<c:when test="${totalPages > 7 && currentNumber <= 4}">
			<c:forEach var="pageNumber" begin="1" end="7">
				<a href="<c:url value="/questions/tags?page=${pageNumber}"/>">${pageNumber}</a>
			</c:forEach>
		</c:when>
		<c:when test="${totalPages > 7 && currentNumber > 4 && currentNumber <= totalPages - 4}">
			<a href="<c:url value="/questions/tags?page=1"/>">1</a>
			<c:forEach var="pageNumber" begin="${currentNumber - 3}" end="${currentNumber + 3}">
				<a href="<c:url value="/questions/tags?page=${pageNumber}"/>">${pageNumber}</a>
			</c:forEach>
			<a href="<c:url value="/questions/tags?page=${totalPages}"/>">{$totalPages}</a>
		</c:when>
		<c:when test="${totalPages > 7 && currentNumber > totalPages - 4}">
			<c:forEach var="pageNumber" begin="${totalPages - 6}" end="${totalPages}">
				<a href="<c:url value="/questions/tags?page=${pageNumber}"/>">${pageNumber}</a>
			</c:forEach>
		</c:when> 
	</c:choose> 
	<c:if test="${currentNumber < totalPages }">
		<a href="<c:url value="/questions/tags?page=${currentNumber+1}"/>">&gt;</a>
	</c:if>
</div>
</c:if>
